package com.two.service.businessman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.two.common.entity.Businessman;
import com.two.common.util.CommonResult;
import com.two.service.businessman.mapper.BusinessmanMapper;
import com.two.service.businessman.service.BusinessmanService;
import com.two.service.businessman.vo.BusinessmanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessmanServiceImpl implements BusinessmanService {

    @Autowired
    private BusinessmanMapper businessmanMapper;

    @Override
    public CommonResult selectByState() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("state",0);
        List list = businessmanMapper.selectList(wrapper);
        return new CommonResult(2000,"查询成功",list);
    }

    @Override
    public CommonResult insertBusinessman(BusinessmanVo businessmanVo) {
        Businessman businessman = new Businessman(null,Integer.parseInt(businessmanVo.getUserid()),businessmanVo.getRestaurantname(),businessmanVo.getAddress(),businessmanVo.getPhone(),businessmanVo.getRemark(),businessmanVo.getUrl(),0);
        int insert = businessmanMapper.insert(businessman);
        if (insert==1){
            return new CommonResult(2000,"申请入驻成功,请等待管理员审核",null);
        }
        return new CommonResult(5000,"申请入驻失败,请联系管理员",null);
    }

    @Override
    public CommonResult updateStateById(BusinessmanVo businessmanVo) {
        Businessman businessman = new Businessman();
        businessman.setId(businessmanVo.getId());
        businessman.setState(1);
        int update = businessmanMapper.updateById(businessman);
        if (update==1){
            return new CommonResult(2000,"审核通过成功",null);
        }
        return new CommonResult(5000,"审核通过失败,请联系管理员",null);
    }

    @Override
    public CommonResult updateState(BusinessmanVo businessmanVo) {
        Businessman businessman = new Businessman();
        businessman.setId(businessmanVo.getId());
        businessman.setState(2);
        int update = businessmanMapper.updateById(businessman);
        if (update==1){
            return new CommonResult(2000,"驳回成功",null);
        }
        return new CommonResult(5000,"驳回失败",null);
    }


}
